package batch;

import org.apache.flink.api.java.DataSet;
import org.apache.flink.api.java.ExecutionEnvironment;
import org.apache.flink.api.java.tuple.Tuple2;

import java.util.ArrayList;

public class operator_groupby {
    public static void main(String[] args) throws Exception {
    //    创建运行环境
        ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    //    获取数据
        ArrayList<Tuple2<Integer,String>> data1 = new ArrayList<Tuple2<Integer,String>>();
        data1.add(new Tuple2<Integer, String>(1,"bing"));
        data1.add(new Tuple2<Integer, String>(2,"shui"));
        data1.add(new Tuple2<Integer, String>(3,"fan"));
        data1.add(new Tuple2<Integer, String>(4,"hong"));
        data1.add(new Tuple2<Integer, String>(2,"yang"));
        data1.add(new Tuple2<Integer, String>(3,"hong"));
        data1.add(new Tuple2<Integer, String>(3,"hongyang"));




        DataSet<Tuple2<Integer,String>> source =  env.fromCollection(data1);

//分组：按照第一个字段进行分组，取出每组中的两条记录
       source.groupBy(0).first(2).print();

    }
}
